import socket


def unix_socket_client(socket_path):
    # 创建一个 Unix Socket 客户端
    client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    
    try:
        # 连接到服务器
        client_socket.connect(socket_path)
        print(f"Connected to server at {socket_path}")
        
        # 发送数据
        message = "Hello, Server!"
        client_socket.sendall(message.encode('utf-8'))
        print(f"Sent message to server: {message}")
        
        # 接收服务器的响应
        response = client_socket.recv(1024)
        print(f"Received response from server: {response.decode('utf-8')}")
    
    except Exception as e:
        print(f"An error occurred: {e}")
    
    finally:
        # 关闭客户端套接字
        client_socket.close()
        print("Client socket closed")

# 使用示例
if __name__ == "__main__":
    unix_socket_client("/tmp/unix_socket")